<template>
  <div class="userReport">
    <el-card shadow="hover">
      <div class="searchBox">
        <div class="itemBox">
          <el-input placeholder="请输入内容" v-model="content">
            <template slot="prepend">举报人ID</template>
          </el-input>
          <el-input placeholder="请输入内容" v-model="number">
            <template slot="prepend">举报序号</template>
          </el-input>
          <el-button class="btn" @click="reportSearchBth">搜索</el-button>
        </div>
      </div>
      <!-- <div class="p">
        <p :class="{ active: index == 0 }" @click="activeStatusA()">未审核</p>
        <p :class="{ active: index == 1 }" @click="activeStatusB()">已审核</p>
      </div> -->
      <el-radio-group v-model="index" fill="#39383D" @change="indexChange">
        <el-radio-button :label="0">未审核</el-radio-button>
        <el-radio-button :label="1">已审核</el-radio-button>
      </el-radio-group>

      <!-- 未审核 -->
      <div>
        <el-table :data="tableDataA" style="width: 100%">
          <el-table-column prop="id" label="举报序号"> </el-table-column>
          <el-table-column prop="create_time" label="举报时间">
          </el-table-column>
          <el-table-column
            prop="auditTime"
            label="审核时间"
            :key="Math.random()"
            v-if="index == 1"
          >
          </el-table-column>
          <el-table-column prop="user_id" label="举报人ID"> </el-table-column>
          <el-table-column prop="nickname" label="举报人"> </el-table-column>
          <el-table-column prop="report_user_id" label="举报对象ID">
          </el-table-column>
          <el-table-column prop="report_nickname" label="举报对象">
          </el-table-column>
          <el-table-column prop="report_content" label="举报内容">
          </el-table-column>
          <el-table-column prop="report_annex" label="附件">
            <template slot-scope="scope">
              <el-badge
                :value="scope.row.report_annex.length"
                class="item"
                type="info"
              >
                <el-image
                  style="width: 80px; height: 100px"
                  :src="scope.row.report_annex[0]"
                  :preview-src-list="scope.row.report_annex"
                >
                </el-image>
              </el-badge>
            </template>
          </el-table-column>
          <el-table-column prop="violations" label="核实违规次数">
          </el-table-column>
          <el-table-column
            prop="reason"
            label="审核结果"
            :key="Math.random()"
            v-if="index == 1"
          >
            <template slot-scope="scope">
              {{
                scope.row.status == 1
                  ? "判定未违规"
                  : scope.row.status == 2
                  ? "判定违规"
                  : "未审核"
              }}
            </template>
          </el-table-column>
          <el-table-column label="处理" width="240">
            <template slot-scope="scope">
              <el-button
                v-if="index == 0"
                size="mini"
                type="success"
                plain
                @click="handleBtn(scope.row)"
                >处理</el-button
              >
              <el-button
                v-else
                size="mini"
                @click="personalThoughtsDetails(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="page"
          :limit.sync="pageSize"
          @pagination="shUserReportShList"
        />
      </div>

      <!-- 处理弹框 -->
      <el-dialog
        :title="index == 0 ? '举报处理' : '举报详情'"
        center
        :visible.sync="dialogVisible"
        width="32%"
      >
        <div>
          <p class="p">
            <span> 举报序号 </span>
            <el-input
              disabled
              v-model="id"
              placeholder="请输入举报序号"
            ></el-input>
            <span> 举报时间 </span>
            <el-input
              disabled
              v-model="create_time"
              placeholder="请输入举报序号"
            ></el-input>
          </p>
          <p class="p">
            <span> 举报人ID </span>
            <el-input
              disabled
              v-model="user_id"
              placeholder="请输入举报人ID"
            ></el-input>
            <span> 举报人 </span>
            <el-input
              disabled
              v-model="nickname"
              placeholder="请输入举报人"
            ></el-input>
          </p>
          <p class="p">
            <span> 被举报人ID </span>
            <el-input
              disabled
              v-model="report_user_id"
              placeholder="请输入被举报人ID"
            ></el-input>
            <span> 被举报人 </span>
            <el-input
              disabled
              v-model="report_nickname"
              placeholder="请输入被举报人"
            ></el-input>
          </p>
          <p class="p1">
            <span> 举报内容 </span>
            <!-- <el-input
              disabled
              v-model="report_content"
              placeholder="请输入被举报人ID"
            ></el-input> -->
            <i>{{ report_content }}</i>
          </p>
          <p class="p1">
            <span></span>
            <!-- <img :src="report_annex" alt="" /> -->
            <el-image
              class="img"
              v-for="(item, index) in report_annex"
              :key="index"
              style="width: 80px; height: 100px"
              :src="item"
              :preview-src-list="report_annex"
            >
            </el-image>
          </p>
          <p class="p1">
            <span> 违规判定 </span>
            <el-radio v-model="violationRadio" :disabled="index == 1" :label="1"
              >用户未违规</el-radio
            >
            <el-radio v-model="violationRadio" :disabled="index == 1" :label="2"
              >用户违规</el-radio
            >
          </p>
          <p class="p1" v-show="violationRadio == 2">
            <span> 举报处理 </span>
            <el-radio v-model="reportRadio" :disabled="index == 1" :label="1"
              >警告</el-radio
            >
            <el-radio v-model="reportRadio" :disabled="index == 1" :label="2"
              >封禁</el-radio
            >
          </p>
          <p class="p1" v-show="violationRadio == 2">
            <span> 违规原因 </span>
            <el-radio-group v-model="reasonRadio">
              <el-radio
                v-for="i in radioList"
                :disabled="index == 1"
                :key="i.id"
                :label="i.id"
                >{{ i.name }}</el-radio
              >
            </el-radio-group>
          </p>
          <p class="p1" v-show="reportRadio == 2 && violationRadio == 2">
            <span> 封禁天数 </span>
            <el-radio v-model="dayRadio" :disabled="index == 1" :label="1"
              >1天</el-radio
            >
            <el-radio v-model="dayRadio" :disabled="index == 1" :label="3"
              >3天</el-radio
            >
            <el-radio v-model="dayRadio" :disabled="index == 1" :label="7"
              >7天</el-radio
            >
            <el-radio v-model="dayRadio" :disabled="index == 1" :label="0"
              >永久</el-radio
            >
          </p>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button
            type="primary"
            @click="reportConfirmationBtn"
            v-if="index == 0"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // 分页
import { shUserReportShList, shUserReportSh } from "@/api/AuditManagement";
import { userBanReasonList } from "@/api/UserManagement";

export default {
  components: { Pagination },
  inject: ["reload"],
  data() {
    return {
      index: 0,
      content: "",
      number: "",

      //未审核
      tableDataA: [],
      total: 0,
      page: 1, //页码
      pageSize: 10, //每页条数

      //处理按钮弹框
      dialogVisible: false,
      id: "",
      create_time: "",
      user_id: "",
      nickname: "",
      report_user_id: "",
      report_nickname: "",
      report_content: "",
      report_annex: "",
      violationRadio: "", //违规判定
      reportRadio: "", //举报处理
      reasonRadio: "", //违规原因
      dayRadio: "", //封禁天数
      radioList: [], //封禁账号值
    };
  },
  methods: {
    //获取列表
    shUserReportShList() {
      shUserReportShList({
        page: this.page,
        pageSize: this.pageSize,
        status: this.index, //0.待审核 1.已审核
        content: this.content, //搜索内容
        number: this.number, //搜索序号
      }).then((res) => {
        if (res.code == 0) {
          this.tableDataA = res.data.list;
          this.total = res.data.total;
          //更新菜单上的红点信息
          this.$store.dispatch("badge/updateValue");
          // for (let i = 0; i < this.tableDataA.length; i++) {
          //   var item = this.tableDataA[i];
          //   if (item.status == 0) {
          //     item.status = "待处理";
          //   } else if (item.status == 1) {
          //     item.status = "通过";
          //   } else {
          //     item.status = "违规";
          //   }
          // }
        }
      });
    },
    //未审核
    // activeStatusA() {
    //   this.index = 0;
    //   shUserReportShList({
    //     page: this.page,
    //     pageSize: this.pageSize,
    //     status: this.index, //0.待审核 1.已审核
    //     content: this.content, //搜索内容
    //     number: this.number, //搜索序号
    //   }).then((res) => {
    //     if (res.code == 0) {
    //       this.tableDataA = res.data.list;
    //       this.total = res.data.total;
    //       for (let i = 0; i < this.tableDataA.length; i++) {
    //         var item = this.tableDataA[i];
    //         if (item.status == 0) {
    //           item.status = "待处理";
    //         } else if (item.status == 1) {
    //           item.status = "通过";
    //         } else {
    //           item.status = "违规";
    //         }
    //       }
    //     }
    //   });
    // },
    // //未审核分页
    // getList() {
    //   this.index = 0;
    //   shUserReportShList({
    //     page: this.page,
    //     pageSize: this.pageSize,
    //     status: this.index, //0.待审核 1.已审核
    //     content: this.content, //搜索内容
    //     number: this.number, //搜索序号
    //   }).then((res) => {
    //     if (res.code == 0) {
    //       this.tableDataA = res.data.list;
    //       this.total = res.data.total;
    //       for (let i = 0; i < this.tableDataA.length; i++) {
    //         var item = this.tableDataA[i];
    //         if (item.status == 0) {
    //           item.status = "待处理";
    //         } else if (item.status == 1) {
    //           item.status = "通过";
    //         } else {
    //           item.status = "违规";
    //         }
    //       }
    //     }
    //   });
    // },
    //未审核 处理按钮
    handleBtn(row) {
      this.id = row.id;
      this.create_time = row.create_time;
      this.user_id = row.user_id;
      this.nickname = row.nickname;
      this.report_user_id = row.report_user_id;
      this.report_nickname = row.report_nickname;
      this.report_content = row.report_content;
      this.report_annex = row.report_annex;
      this.dialogVisible = true;
      userBanReasonList({}).then((res) => {
        if (res.code == 0) {
          this.radioList = res.data;
        }
      });
      this.violationRadio = 1;
      this.reportRadio = 1;
      this.reasonRadio = 1;
      this.dayRadio = 1;
    },
    //处理确认按钮
    reportConfirmationBtn() {
      if (this.violationRadio == 1) {
        this.reportRadio = 1;
        this.reasonRadio = 1;
        this.dayRadio = 1;
      }
      shUserReportSh({
        id: this.id,
        ban: this.violationRadio, //1.未违规 2.违规
        handlerType: this.reportRadio, //处理类型 1.警告 2.封禁账号
        reasonType: this.reasonRadio, //原因id
        days: this.dayRadio, //封禁账号天数
      }).then((res) => {
        if (res.code == 0) {
          this.$message({
            message: "处理成功",
            type: "success",
          });
          this.reload();
          this.dialogVisible = false;
        }
      });
    },
    //详情按钮
    personalThoughtsDetails(row) {
      this.id = row.id;
      this.create_time = row.create_time;
      this.user_id = row.user_id;
      this.nickname = row.nickname;
      this.report_user_id = row.report_user_id;
      this.report_nickname = row.report_nickname;
      this.report_content = row.report_content;
      this.report_annex = row.report_annex;
      this.dialogVisible = true;
      userBanReasonList({}).then((res) => {
        if (res.code == 0) {
          this.radioList = res.data;
        }
      });
      //判定违规还是未违规
      if (row.status == 1) {
        this.violationRadio = 1;
      }
      if (row.status == 2) {
        this.violationRadio = 2;
        this.reasonRadio = parseInt(row.audit_info.reason);
        this.reportRadio = parseInt(row.audit_info.type);
        this.dayRadio = parseInt(row.audit_info.days);
      }
    },
    // //已审核
    // activeStatusB() {
    //   this.index = 1;
    //   shUserReportShList({
    //     page: this.pageB,
    //     pageSize: this.pageSizeB,
    //     status: this.index, //0.待审核 1.已审核
    //     content: this.content, //搜索内容
    //     number: this.number, //搜索序号
    //   }).then((res) => {
    //     if (res.code == 0) {
    //       this.tableDataB = res.data.list;
    //       this.totalB = res.data.total;
    //       for (let i = 0; i < this.tableDataB.length; i++) {
    //         var item = this.tableDataB[i];
    //         if (item.status == 0) {
    //           item.status = "待处理";
    //         } else if (item.status == 1) {
    //           item.status = "通过";
    //         } else {
    //           item.status = "违规";
    //         }
    //       }
    //     }
    //   });
    // },
    //已审核分页
    // getListB() {
    //   this.index = 1;
    //   shUserReportShList({
    //     page: this.pageB,
    //     pageSize: this.pageSizeB,
    //     status: this.index, //0.待审核 1.已审核
    //     content: this.content, //搜索内容
    //     number: this.number, //搜索序号
    //   }).then((res) => {
    //     if (res.code == 0) {
    //       this.tableDataB = res.data.list;
    //       this.totalB = res.data.total;
    //       for (let i = 0; i < this.tableDataB.length; i++) {
    //         var item = this.tableDataB[i];
    //         if (item.status == 0) {
    //           item.status = "待处理";
    //         } else if (item.status == 1) {
    //           item.status = "通过";
    //         } else {
    //           item.status = "违规";
    //         }
    //       }
    //     }
    //   });
    // },
    //搜索
    reportSearchBth() {
      this.page = 1;
      this.shUserReportShList();
    },
    indexChange() {
      this.page = 1;
      this.shUserReportShList();
    },
  },
  created() {
    this.shUserReportShList();
  },
};
</script>

<style lang="less" scoped>
.userReport {
  margin: 30px;
  height: 100%;
  /deep/ .el-table .cell {
    overflow: visible !important;
  }
  .searchBox {
    display: flex;
    margin-bottom: 20px;
    .itemBox {
      display: flex;
      .el-input {
        margin-right: 20px;
        width: 280px;
      }
    }
  }
  .p {
    display: flex;
    align-items: center;
    p {
      width: 100px;
      height: 40px;
      line-height: 40px;
      text-align: center;
    }
    .active {
      background-color: #ec6564;
      color: #fff;
      border-radius: 10px;
    }
    .el-select {
      margin-left: 20px;
    }
  }
  .el-dialog {
    div {
      .p {
        display: flex;
        justify-content: space-between;
        span {
          width: 240px;
          text-align: right;
          line-height: 40px;
          margin-right: 10px;
        }
      }
      .p1 {
        display: flex;
        span {
          width: 100px;
          text-align: right;
          line-height: 40px;
          margin-right: 10px;
        }
        i {
          font-style: normal;
          line-height: 40px;
        }
        .img {
          margin-right: 10px;
        }
        .el-radio {
          line-height: 40px;
        }
      }
    }
  }
}
</style>